﻿Public Class Login
    Inherits System.Web.UI.Page
    Dim connect As New Connection()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
    End Sub

    Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Try


            Session("UserID") = UserName.Text
            Session("Pwd") = Password.Text


            'SELECT T0.[Name], T0.[Code] FROM [dbo].[@USER]  T0 WHERE T0.[U_Pwd]  COLLATE Latin1_General_CS_AS ='Gopi' and  T0.[Code] ='manager' and  isnull(T0.[U_Active] ,'') ='Y'


            If Connection.bConnect = False Then
                connect.setDB(UserName.Text, Password.Text)
                Dim Str As String = connect.connectDB()
                If Str = "" Then
                    Dim oRecordSetBP As SAPbobsCOM.Recordset
                    oRecordSetBP = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    oRecordSetBP.DoQuery("SELECT T0.[Name], T0.[Code] FROM [dbo].[@USER]  T0 WHERE T0.[U_Pwd] COLLATE Latin1_General_CS_AS ='" & Password.Text & "' and  T0.[Code] ='" & UserName.Text & "' and  isnull(T0.[U_Active] ,'') ='Y'")
                    If oRecordSetBP.RecordCount = 0 Then
                        FailureText.Text = "Invalid User ID or Password!"
                    Else
                        Response.Redirect("../ItemMaster.aspx")
                    End If

                Else
                    FailureText.Text = Str
                End If
            Else
                Dim oRecordSetBP As SAPbobsCOM.Recordset
                oRecordSetBP = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSetBP.DoQuery("SELECT T0.[Name], T0.[Code] FROM [dbo].[@USER]  T0 WHERE T0.[U_Pwd] COLLATE Latin1_General_CS_AS ='" & Password.Text & "' and  T0.[Code] ='" & UserName.Text & "' and  isnull(T0.[U_Active] ,'') ='Y'")
                If oRecordSetBP.RecordCount = 0 Then
                    FailureText.Text = "Invalid User ID or Password!"
                Else
                    Response.Redirect("../ItemMaster.aspx")
                End If
                '  Response.Redirect("../ItemMaster.aspx")
            End If
        Catch ex As Exception
            FailureText.Text = ex.Message
        End Try
    End Sub
End Class